#ifndef __IJPEGE_H__
#define __IJPEGE_H__

#include <icommon.h>

#ifdef __cplusplus
extern "C" {
#endif

#define IJPEGE_VERSION	"1.0"
#define	IJPEGE_BUILD		"2015.1.1 - 2015.2.1"

typedef struct ijpege ijpege_t;

/****************************************************************************
 * NAL structure and functions
 ****************************************************************************/
/* The data within the payload is already NAL-encapsulated; the ref_idc and type
 * are merely in the struct for easy access by the calling application.
 * All data returned in an ijpege_nal_t, including the data in p_payload, is no longer
 * valid after the next call to ijpege_encoder_encode.  Thus it must be used or copied
 * before calling ijpege_encoder_encode or ijpege_encoder_headers again.
 */
typedef struct ijpege_nal {
    int     i_payload;
    uint8_t *p_payload;
} ijpege_nal_t;

typedef struct ijpege_param {
	/* soc, buf, device manage */
	int			index;
	int			soc;
	int			b_tlb;
	int			b_use_phy;
	int			b_user_fenc;			/* whether use user buf to hw encode */
	int			b_user_nalbuffer;		/* whether use user nal buf  */
	int			i_devid;

	/* Video Properties */
	int         i_width;
	int         i_height;
	int         i_csp;         /* CSP of encoded bitstream */

    /* Log */
    void        (*pf_log)(const char *module, int i_level, const char *psz, va_list);
    char        *module;
    int         i_log_level;

	/* buf managememt */
	/* must be vitural addr */
	void *(*ckmalloc)(int index, int size, int align);
	void (*ckfree)(int index, void *);
	intptr_t (*ckvirt_to_phys)(intptr_t vaddr);
	intptr_t (*ckphys_to_virt)(intptr_t paddr);
} ijpege_param_t;

enum ijpege_ql {
	IJPEGE_QL_AUTO		= -1,
	IJPEGE_QL_NORMAL		= 0,
	IJPEGE_QL_FINE		= 1,
	IJPEGE_QL_FINER		= 2,
};
typedef struct ijpege_ql_param {
    bool user_ql_en;
    uint8_t qmem_table[128];
} ijpege_ql_param_t;
typedef struct ijpege_pic {
    /* In: force quantizer for != IJPEGE_QL_AUTO */
    int				i_ql;
    /* In: pic_struct, for pulldown/doubling/etc...used only if b_pic_struct=1.
     *     use pic_struct_e for pic_struct inputs
     * Out: pic_struct element associated with frame */
    int				i_pic_struct;
    c_img_t			img;
    /* private user data. copied from input to output frames. */
    void			*opaque;
	uint8_t **nals_buffer;
	int nals_buffer_size;
} ijpege_pic_t;
enum jpege_rcfg_type {
    IJPEGE_RCFG_QL_ID = 0,
};
extern int ijpege_get_param(ijpege_t *h, int param_id, const void *param);
extern int ijpege_set_param(ijpege_t *h, int param_id, const void *param);
extern void ijpege_param_default(ijpege_param_t *param);
extern ijpege_t *ijpege_init(ijpege_param_t *param);
extern int ijpege_encode(ijpege_t *h, ijpege_nal_t **pp_nal, int *pi_nal,
		ijpege_pic_t *pic_in, ijpege_pic_t *pic_out);
extern void ijpege_deinit(ijpege_t *h);
#ifdef __cplusplus
}
#endif

#endif /* __IJPEGE_H__ */
